package com.lxy.token.auto;


import com.auth0.jwt.JWT;
import com.lxy.token.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

//自动配置启动类
@AutoConfiguration
//属性绑定
@EnableConfigurationProperties(value = {TokenProperties.class})
//注入条件   JWT.class这个类存在
@ConditionalOnClass({JWT.class})
//开关变量 ConditionalOnProperty  默认开启
@ConditionalOnProperty(prefix = "token",name = "enabled",matchIfMissing = true)
public class TokenAutoConfigure {

    @Bean
    @ConditionalOnMissingBean(value = {TokenTemplate.class})// 如果容器当中没有TokenTemplate，则将该类注入到容器当中
    public TokenTemplate tokenTemplate(TokenProperties tokenProperties) {
        TokenTemplate tokenTemplate = new TokenTemplate(tokenProperties);
        return tokenTemplate;

    }
}
